/**
 * Created by dengtao on 2017/4/7. 移动端调试工具APPDebugTools v1.0.0
 */
(function () {
    window.APPDebug = {
        config: {debugBlockName: 'debugBlock'},
        init: function () {
            var that = this;
            that.D_body = document.querySelector('body');
            var debugBlock = document.createElement('div');
            debugBlock.setAttribute("id", this.config.debugBlockName);
            debugBlock.setAttribute("style", 'width: 40%;height: 50%;position: fixed;top: 0px;right: 0px;font-size: 18px;overflow-y: scroll;word-break: break-all;z-index: 999999;border: 1px solid #0712cc;');
            debugBlock.innerHTML = '调试信息：';
            /**
             scrollHeight(页面总长)=scrollTop(滚动条距离顶部长度)+clientHeight(页面实际高度)
             */
            window.console.log = function (e) {
                var date = new Date();
                var autoScroll = false;
                //如果滚动在最底部，就自动向下滚动
                if (debugBlock.scrollHeight == (debugBlock.scrollTop + debugBlock.clientHeight )) {
                    autoScroll = true;
                }
                debugBlock.innerHTML = debugBlock.innerHTML + '<div>' + date.getMinutes() + ':' + date.getSeconds() + ':>' + e + '</div>';
                !autoScroll ? '' : document.querySelector('#debugBlock').scrollTop = document.querySelector('#debugBlock').scrollHeight;
            }
            that.D_body.append(debugBlock);
        }
    }
})();
APPDebug.init();